<!-- 企业信息查询 -->
<template>
  <div class="home-page-content">
    <h3 class="mb-20">线下项目备案</h3>
    <Form ref="formData" :model="formData" :label-width="80">
      <Row :gutter="30">
        <Col span="6">
          <FormItem label="项目名称" prop="projectName">
            <Input v-model="formData.projectName" placeholder="请输入"></Input>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="产业标记" prop="industryAssigns">
            <Select v-model="formData.industryAssigns" placeholder="全部" multiple clearable>
              <Option :value="it.name" v-for="(it, index) in industryAssignsList" :key="index">{{ it.name }}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="组织范围" prop="parentOrgId">
            <OrganizationalTree v-model="formData.parentOrgId" />
          </FormItem>
        </Col>

        <Col span="6" class="com-action-search-btn">
          <Button type="primary" icon="md-search" @click="handleSubmit('formData')">查询</Button>
          <BtnPlain type="primary" @click="handleReset('formData')">
            <Icon type="md-refresh" />
            <span>重置</span>
          </BtnPlain>
        </Col>
      </Row>
    </Form>
    <div class="com-action-table-btn">
      <Button type="primary" @click="onAdd('', 'add')">
        <Icon type="md-add" />
        <span>新建备案项目</span>
      </Button>
      <BtnPlain type="error">批量删除</BtnPlain>
    </div>
    <Table :columns="columns" :data="listData" @on-selection-change="onSelectionChange">
      <template slot-scope="{ row }" slot="action">
        <BtnText type="primary" @BtnClick="onView(row)">详情</BtnText>
        <BtnText type="warning" @BtnClick="onAdd(row.busiInfoId,'edit')">修改</BtnText>
        <BtnText type="error" @BtnClick="onDel(row)">删除</BtnText>
      </template>
    </Table>
    <PageAtion
      v-if="formData.total"
      :total="formData.total"
      :size.sync="formData.size"
      :page.sync="formData.page"
      @pageSizeChange="pageSizeChange"
    />
  </div>
</template>

<script>
import { getDictTreeByParentId } from '@/api/system.js'
import OrganizationalTree from '@/pages/components/organizationalTree'
import { projectFilingGetPage, projectFilingDeleteData } from '@/api/projectFiling.js'

export default {
  name: 'projectFiling',
  components: { OrganizationalTree },
  data () {
    return {
      formData: {
        projectName: '',
        industryAssigns: [],
        page: 1,
        size: 10,
        total: 10,
      },
      columns: [
        {
          type: 'selection',
          width: 60
        },
        {
          title: "项目名称",
          key: "projectName",
          minWidth: 160,
          tooltip: true
        },
        {
          title: "业主方",
          key: "ownerCompanyName",
          minWidth: 160,
        },
        {
          title: "施工方",
          key: "constructionName",
          minWidth: 160,
        },
        {
          title: "项目地址",
          key: "projectAddressName",
          minWidth: 240,
          tooltip: true
        },
        {
          title: "预计产值规模(万元)",
          key: "outputScale",
          minWidth: 160,
        },
        {
          title: "发布时间",
          key: "publishTime",
          minWidth: 170,
        },
        {
          title: '操作',
          slot: 'action',
          width: 170,
          align: 'center',
          fixed: 'right'
        },
      ],
      listData: [],
      industryAssignsList: [],
      ids: []
    };
  },
  async created () {
    this.init()
    this.industryAssignsList = await getDictTreeByParentId({ parentId: 'COMPANY_SERVICE' })
  },
  methods: {
    async init () {
      const request = {
        ...this.formData
      }
      const { data, page, size, total } = await projectFilingGetPage(request)
      this.listData = data
      this.formData = { ...this.formData, ...{ page, size, total } }
    },
    onAdd (busiInfoId = '', type = 'add') {
      this.$router.push({ path: '/projectFilingAdd', query: { busiInfoId, type } })
    },
    handleReset (name) {
      this.$refs[name].resetFields();
      this.init()
    },
    handleSubmit (name) {
      this.init()
    },
    onDel ({ busiInfoId }) {
      this.del([busiInfoId])
    },
    onBatchDel () {
      this.del(this.ids)
    },
    del (busiInfoIds) {
      this.$Modal.confirm({
        title: "温馨提示",
        content: '该数据删除后不可恢复，请确认是否继续？',
        onOk: async () => {
          await projectFilingDeleteData({ busiInfoIds })
          this.$Message.success({
            background: true,
            content: '操作成功！'
          });
          this.init()
        },
      })
    },
    pageSizeChange () {
      this.init()
    },
    // table勾选事件
    onSelectionChange (selection) {
      this.ids = selection.map(it => it.busiInfoId)
    },
    onView (row) {
      const { busiInfoId } = row
      this.$router.push({ path: '/projectFilingDetails', query: { busiInfoId } })
    },
  },
};
</script>

<style lang="less" scoped>
.mb-20 {
  margin-bottom: 20px;
}
</style>
